<?php
error_reporting(0);
$isadmin=1; 
include '../comm/config.php';
include '../data/config.inc.php';
include '../include/db_mysql.class.php';
include 'check.php';
include '../comm/checkpostandget.php';
//($dbserver, $dbuser, $dbpass, $dbname, $pconnect);
include '../uc_client/client.php';

function sql_insert_one($uc_pre, $table, $filed_arr) {
	$field = "";
	$values = "";
	foreach ($filed_arr as $k => $v) {
		$field = "`" . $k . "`," . $field;
		$values = "'" . $v . "'," . $values;
	}
	$field = substr($field, 0, strlen($field) - 1);
	$values = substr($values, 0, strlen($values) - 1);
	$sql = "insert into $uc_pre$table($field) values ($values);";
	$query = mysql_query($sql);
	if ($query)
		return 1;
	else
		return mysql_error();
}

function sql_count($table, $count_field, $wh_field, $wh_value, $and = '') { //and为自定义的筛选条件 例：$and='and id=1'
	global $BIAOTOU;
	$sql = "select count($count_field) from $BIAOTOU$table where $wh_field='$wh_value' " . $and;
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row[0] ? $row[0] : 0;
}

$link = mysql_connect($dbserver, $dbuser, $dbpass);
mysql_query("set names utf8");
mysql_select_db($dbname);

$num = sql_count("user", "id", 1, 1);
$onLoad = 0;
//$limit = !($_GET['limit']) ? '1' : intval($_GET['limit']);
//$limit2 = ($limit -1) * $_GET['size'];
$_GET['limit'] = !($_GET['limit']) ? '0' : intval($_GET['limit']);
if ($_GET['sub']) {
	$onLoad = 0;
	$sql = "select * from " . $BIAOTOU . "user limit " . $_GET['limit'] . "," . $_GET['size'];
	$query = mysql_query($sql);
	if ($query) {
		while ($row = mysql_fetch_array($query)) {
			$salt = substr(uniqid(rand()), -6);
			$pwd = md5($row['ddpassword'].$salt);
			$filed_arr = array (
				'uid' => $row['Id'],
				'username' => $row['ddusername'],
				'password' => $pwd,
				'email' => $row['email'],
				'regip' => '127.0.0.1',
				'regdate' => mktime($row['regtime']
			), 'salt' => $salt);
			$link = mysql_connect('localhost', UC_DBUSER, UC_DBPW);
			mysql_query("set names utf8");
			mysql_select_db(UC_DBNAME);
			
			sql_insert_one(UC_DBTABLEPRE, "members", $filed_arr);
			$filed_row = array ('uid' => $row['Id'],'blacklist' => '');
			sql_insert_one(UC_DBTABLEPRE, "memberfields", $filed_row);
			
			$link = mysql_connect($dbserver, $dbuser, $dbpass);
			mysql_query("set names utf8");
			mysql_select_db($dbname);
			
		}
		$_GET['limit'] = $_GET['limit'] + $_GET['size'];
		$onLoad = 1;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.STYLE3 {color: #FF0000}
-->
</style>
</head>

<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
              <td height="30" colspan="2" bgcolor="E9F2FB" class="bigtext"><strong>&nbsp;<img src="images/arrow.gif" width="16" height="22" align="absmiddle" />多多-UC 会员导入</strong></td>
            </tr>
            <tr>
              <td width="100%" colspan="2" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><form action="" method="get" name="form">
                    <br />
                    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr>
                        <td height="40" class="bigtext"><span style="font-weight:bold; color:#F00">提示：</span><?php if($_GET['limit']>=$num){echo '<b style="color:red">会员导入完毕</b>';}else{echo "网站现有会员".$num."人，已导入会员".$_GET['limit']."人";} ?>
                        <br/><span style="font-weight:bold; color:#F00">注意：</span>网站ID为1的会员，因为与UenterC中的管理员ID冲突，无法导入
                        <br/><span style="font-weight:bold; color:#F00; font-size:18px">必读：</span>为了防止出现不必要的错误，最好先在UCenter中更新数据缓存，<br/>
                        <span style="font-weight:bold; color:#FFF; font-size:18px">必读：</span>在UCenter左侧的功能管理中，倒数第二个“更新缓存”
                        
                        </td>
                      </tr>
                    </table>
                    <table width="600"  align="center" border=1 cellpadding=0 cellspacing=0
style="border-collapse: collapse" bordercolor="#dddddd">
                      <tr>
                        <td height="30" align="right" class="bigtext">每轮导入会员：</td>
                        <td height="0" class="bigtext">&nbsp;<input style="width:30px" type="text" name="size" value="<?=$_GET['size']?>"/>(个)根据您的网速，每轮导入会员个数建议设置100-1000之间</td>
                        </tr>
                      
                      <tr>
                        <td height="30" align="right">&nbsp;</td>
                        <td height="30" class="bigtext">&nbsp;
						<input type="submit" name="sub" value="提交"  <?php if($_GET['limit']>=$num){echo 'disabled="disabled"';}?>/>                           </td>
                      </tr>
                    </table>
                    <br />
                    <input type="hidden" name="limit" value="<?=$_GET['limit']?>" />
                  </form>
                  </td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
      
    </table></td>
  </tr>
</table>
</body>
</html>
<?php mysql_close($link);?>
